package com.szqhyxj.youxiangju.biz.partnerHome.home;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.szqhyxj.youxiangju.BasePromptFragment;
import com.szqhyxj.youxiangju.R;
import com.szqhyxj.youxiangju.biz.partnerHome.home.fragment.partnerequipment.PartnerEquipmentPaymentFragment;
import com.szqhyxj.youxiangju.biz.partnerHome.home.fragment.partnerfast.PartnerFastPaymentFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by leung on 2018/10/31.
 */

public class PartnerHomeFragment extends BasePromptFragment implements PartnerHomeContract.View{

    Unbinder unbinder;
    @BindView(R.id.containerPartner)
    ViewPager containerPartner;
    @BindView(R.id.equipment_icon)
    ImageView equipmentIcon;
    @BindView(R.id.equipment_title)
    TextView equipmentTitle;
    @BindView(R.id.fast_icon)
    ImageView fastIcon;
    @BindView(R.id.fast_title)
    TextView fastTitle;
    @BindColor(R.color.gray)
    int colorNormal;
    @BindColor(R.color.invitationColor)
    int colorSelected;
    @BindView(R.id.equipment_bottom)
    View equipmentBottom;
    @BindView(R.id.fast_bottom)
    View fastBottom;
    private List<Fragment> fragments = new ArrayList<>();
    PartnerHomePresenter presenter;

    public static PartnerHomeFragment newInstance() {
        Bundle args = new Bundle();
        PartnerHomeFragment fragment = new PartnerHomeFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_partner_home;
    }

    @Override
    protected void start(){
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        presenter = new PartnerHomePresenter(this);
        presenter.init();
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void showAll() {
        fragments.clear();
        fragments.add(PartnerEquipmentPaymentFragment.newInstance());
        fragments.add(PartnerFastPaymentFragment.newInstance());
        containerPartner.setAdapter(new PartnerHomeContainer(getChildFragmentManager(), fragments));
        containerPartner.setOffscreenPageLimit(2);
    }

    @Override
    public void showEquipment() {
        containerPartner.setCurrentItem(0, false);
        reset();
        equipmentTitle.setTextColor(colorSelected);
        equipmentBottom.setBackgroundColor(colorSelected);
    }

    @Override
    public void showFast() {
        containerPartner.setCurrentItem(1, false);
        reset();
        fastTitle.setTextColor(colorSelected);
        fastBottom.setBackgroundColor(colorSelected);
    }

    private void reset() {
        equipmentTitle.setTextColor(colorNormal);
        fastTitle.setTextColor(colorNormal);
        equipmentBottom.setBackgroundColor(getResources().getColor(R.color.white));
        fastBottom.setBackgroundColor(getResources().getColor(R.color.white));
    }


    @OnClick({R.id.equipment_partner, R.id.fast_partner})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.equipment_partner:
                presenter.setEquipment();
                break;
            case R.id.fast_partner:
                presenter.setFast();
                break;
        }
    }

    @Override
    public void navTorepaymentperformance() {

    }

    @Override
    public void navTocollectionperformance() {

    }

    @Override
    public void navToactivationreward() {

    }
}